package com.huyanqi.front.rest.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.huyanqi.core.RetdCodeType;
import com.huyanqi.core.RetdObj;
import com.huyanqi.core.service.impl.BaseFrontServiceImpl;
import com.huyanqi.dao.CommentDAO;
import com.huyanqi.entity.Comment;
import com.huyanqi.front.rest.service.CommentRestService;

@Service("CommentRestService")
public class CommentRestImpl extends BaseFrontServiceImpl<Comment,Long, CommentDAO> implements CommentRestService{

	@Override
	@Resource(name="CommentDAO")
	public void setEntityDao(CommentDAO entityDao) {
		this.entityDao=entityDao;
	}

	@Override
	public RetdObj<List<Comment>> findComments(Long cid) {
		RetdObj<List<Comment>> retd = new RetdObj<List<Comment>>();
		List<Comment> list = entityDao.executeQuery("SELECT new Comment(c.cmId,c.cmContent,c.cmTime,c.cmSid,c.cmUp,c.cmUid,u.uHead,u.uNickname) FROM Comment c,User u WHERE c.cmUid = u.uId AND c.cmSid = ? ORDER BY c.cmTime ASC", cid);
		if(list.size()>0){
			retd.setRealObj(list);
			retd.setCode(RetdCodeType.PASS_OK);
		}else{
			retd.setCode(RetdCodeType.PASS_NODATA);
		}
		return retd;
	}

}
